package com.example.pc.videodemo;

import android.content.Context;
import android.util.Log;

import java.lang.reflect.Method;

public class HookUtil {
    //设置系统默认通话应用
    public static final String CLASS_SMS_MANAGER = "android.telecom.DefaultDialerManager";
    //设置默认通话应用
    public static final String METHOD_SET_DEFAULT = "setDefaultDialerApplication";
    //获取当前默认通话应用
    public static final String METHOD_GET_DEFAULT = "getDefaultDialerApplication";

    /**
     * 设置当前默认通话应用
     *
     * @param context
     * @param packageName 应用包名
     */
    public static void setDefaultDialerApplication(Context context, String packageName) {
        try {
            Class smsClass = Class.forName(CLASS_SMS_MANAGER);
            Method method = smsClass.getMethod(METHOD_SET_DEFAULT, Context.class, String.class, int.class);
            Object ob = method.invoke(null, context, packageName, 0);
            Log.d("HookUtil", "setDefaultDialerApplication success:" + ob.toString());
        } catch (Exception e) {
            e.printStackTrace();
            Log.d("HookUtil","setDefaultSmsApplication error:"+ e.getMessage());
        }
    }

    /**
     * 获取当前默认通话应用
     *
     * @param context
     */
    public static void getDefaultDialerApplication(Context context) {
        try {
            Class smsClass = Class.forName(CLASS_SMS_MANAGER);
            Method method = smsClass.getMethod(METHOD_GET_DEFAULT, Context.class);
            Object ob = method.invoke(null, context);
            Log.d("HookUtil", "getDefaultDialerApplication success:" + ob.toString());
        } catch (Exception e) {
            e.printStackTrace();
            Log.d("HookUtil","getDefaultDialerApplication error:" +e.getMessage());
        }
    }



}


